/*
 * 版权所有(c)  1952110078@qq.com  2022 - 2022
 */

package com.ldc.module_main.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.ldc.commonlibs.common.ViewModelBase;
import com.ldc.commonlibs.http.NetCallback;
import com.ldc.commonlibs.http.RetrofitClient;
import com.ldc.module_main.model.UserPlayListModel;
import com.ldc.module_main.net.HttpService;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liudc
 * @since 2022/7/22 23:01
 */
public class UserPlayViewModel extends ViewModelBase {
    private final HttpService apiService = RetrofitClient.getInstance().getService(HttpService.class);
    private MutableLiveData<UserPlayListModel> _userPlayListModel = new MutableLiveData<>();

    public MutableLiveData<UserPlayListModel> getUserPlayListModel() {
        return _userPlayListModel;
    }

    public void userPlay(int offset, String userId) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("uid", userId);
        params.put("offset", offset);
        getNetDataSource(apiService.userPlay(params), new NetCallback<UserPlayListModel>() {
            @Override
            public void onReceiver(UserPlayListModel data) {
                _userPlayListModel.setValue(data);
            }

            @Override
            public void onBadReceiver(Throwable throwable) {
                _userPlayListModel.setValue(null);
            }
        });
    }
}
